package com.xyg.product.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.xyg.common.model.DataEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * spu
 * @author Administrator
 *
 */
@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name="xyg_product")
public class Product extends DataEntity<Product, Long> {

	private String name;
	
	private String keywords;
	
	@ManyToOne(fetch=FetchType.LAZY)
	private Category category;
	
	@ManyToOne(fetch=FetchType.LAZY)
	private Brand brand;
	
	@ManyToOne(fetch=FetchType.LAZY)
	private Template template;
	
	/** 商品 */
	@OneToMany(mappedBy = "product", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
	private Set<Goods> goods = new HashSet<>();
	
	/**参数*/
	@ElementCollection(fetch = FetchType.LAZY)
	@CollectionTable(name = "xyg_product_param")
	private Map<Property,String> params = new HashMap<>();

	/** 展示图片 */
	@ElementCollection(fetch=FetchType.LAZY)
	@CollectionTable(name = "xyg_product_showimage")
	private List<Image> showImages = new ArrayList<>();
	
	/** 详情图片 */
	@ElementCollection(fetch=FetchType.LAZY)
	@CollectionTable(name = "xyg_product_detailimage")
	private List<Image> detailImages = new ArrayList<>();
	
	@ManyToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	private List<PropertyValue> propertyValues = new ArrayList<>();
	
}
